package nl.nhl.idp.Components;

import java.util.List;

import nl.nhl.idp.R;
import nl.nhl.idp.Components.Database.Session;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class SessionAdapter extends ArrayAdapter<Session>
{
    private List<Session> items;
    private Context context;

    public SessionAdapter(Context context, int textViewResourceId, List<Session> list) 
    {
    	super(context, textViewResourceId, list);
        this.items = list;
        this.context = context;
    }
    
    @Override
    public void clear()
    {
    	items.clear();
    }
    
    public Session GetItem(int index)
    {
    	return items.get(index);
    }

    public void Add(Session session)
    {
    	items.add(session);
    }
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent) 
    {
            View v = convertView;
            if (v == null) 
            {
                LayoutInflater vi = (LayoutInflater)this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                v = vi.inflate(R.layout.list_row_session, null);
            }
            
            Session o = items.get(position);
            //v.setTag(o);
            
            if (o != null) 
            {
            		TextView tt = (TextView) v.findViewById(R.id.row_id);
                    TextView bt = (TextView) v.findViewById(R.id.start);
                    TextView et = (TextView) v.findViewById(R.id.end);
                    
                    if(tt != null)
                    {
                    	tt.setText(""+o.getID());
                    }
                    
                    if(bt != null)
                    {
                          bt.setText("Start: " + o.getStartTime());
                    }
                    
                    if(et != null)
                    {
                    	et.setText("End: " + o.getEndTime());
                    }
            }
            
            return v;
    }
}
